package com.xzx.mr.sort;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @author xinzhixuan
 * @version V1.0
 * @date 2019/7/21 12:01
 */
public class ProvincePartitioner extends Partitioner<FlowBean, Text> {
    @Override
    public int getPartition(FlowBean key, Text value, int numPartitions) {
        // value是手机号
        String phone = value.toString();
        int partition = 4;
        if (StringUtils.isNotBlank(phone) && phone.length() > 3) {
            switch (phone.substring(0, 3)) {
                case "136":
                    partition = 0;
                    break;
                case "137":
                    partition = 1;
                    break;
                case "138":
                    partition = 2;
                    break;
                case "139":
                    partition = 3;
                    break;
            }
        }
        return partition;
    }
}
